package com.tepth.maintenancesystem.presenter;

import android.content.Context;
import android.support.v4.content.ContextCompat;
import android.support.v7.widget.CardView;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.FrameLayout;
import android.widget.TextView;

import com.tepth.maintenancesystem.R;
import com.tepth.maintenancesystem.bean.CompletedObj;
import com.tepth.maintenancesystem.untils.DimensionConvert;

import java.util.List;

/**
 * Created by ishratkhan on 24/02/16.
 */
public class CompletedAdapter extends RecyclerView.Adapter<CompletedAdapter.AlarmCompletedDetailsHolder> {

    List<CompletedObj> data;
    Context mContext;

    public CompletedAdapter(Context con, List<CompletedObj> data) {
        mContext = con;
        this.data = data;
    }

    @Override
    public AlarmCompletedDetailsHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        View view = LayoutInflater.from(mContext).inflate(R.layout.alarm_completed_details, null);
        return new AlarmCompletedDetailsHolder(view);
    }

    @Override
    public void onBindViewHolder(AlarmCompletedDetailsHolder detailsHolder, int position) {
        CompletedObj obj = data.get(position);
        detailsHolder.part.setText(obj.getName());
        ViewGroup.LayoutParams params=detailsHolder.rv_item_card.getLayoutParams();
        params.width= DimensionConvert.getWidth(mContext);
        detailsHolder.rv_item_card.setLayoutParams(params);
        switch (obj.getLevel()) {
            case 0:
                detailsHolder.rv_item_card.setBackgroundColor(ContextCompat.getColor(mContext,R.color.calendar_bg));
                detailsHolder.part.setTextColor(ContextCompat.getColor(mContext,R.color.white));
                detailsHolder.details.setVisibility(View.GONE);
                detailsHolder.time.setVisibility(View.GONE);
                break;
            case 1:
                detailsHolder.details.setText(obj.getDetails());
                detailsHolder.time.setText(obj.getTime());
                detailsHolder.rv_item_card.setBackgroundColor(ContextCompat.getColor(mContext,R.color.white));
                detailsHolder.part.setTextColor(ContextCompat.getColor(mContext,R.color.black));
                detailsHolder.details.setVisibility(View.VISIBLE);
                detailsHolder.time.setVisibility(View.VISIBLE);
                break;
            default:
                break;
        }

    }

    @Override
    public int getItemCount() {
        return data.size();
    }

    static class AlarmCompletedDetailsHolder extends RecyclerView.ViewHolder {
        TextView part, details, time;
        CardView rv_item_card;

        public AlarmCompletedDetailsHolder(View itemView) {
            super(itemView);
            part = (TextView) itemView.findViewById(R.id.completed_part);
            details = (TextView) itemView.findViewById(R.id.completed_details);
            time = (TextView) itemView.findViewById(R.id.completed_time);
            rv_item_card = (CardView) itemView.findViewById(R.id.rv_item_card);
        }

    }
}
